home *** CD-ROM | disk | FTP | other *** search
/ Hobby PC 32 / Hobby PC 32.iso / extras / WIN31 / DATA.Z / VUTILITY.INC < prev    next >
Text File  |  1994-10-25  |  8KB  |  296 lines

  1. '----------------------------------------------------------------
  2. '- more specialized little functions to make our lives easier.
  3. '- John Alspaugh 13OCT94
  4. '- Copyright 1993-1994 Virtus Corporation.  All Rights Reserved.
  5. '-
  6. '- Note that this must be included after MSDETECT.INC and SETUPAPI.INC
  7. '-
  8. '----------------------------------------------------------------
  9. 'simple utility include.
  10.  
  11. '' dialog number
  12. CONST LOOKFORFILE_DLG    = 6352
  13. CONST NO_WIN_3_1_DLG     = 410
  14. CONST WRONG_CPU_DLG     = 411
  15.  
  16.  
  17. DECLARE SUB VMessageBox(msg$, title$)
  18. DECLARE SUB VDbgMsgBox(msg$, title$)
  19. DECLARE FUNCTION VMakePath (szDir$, szFile$) AS STRING
  20. DECLARE SUB VMaximizeFrame
  21. DECLARE FUNCTION VFindExeFromRegistration(pFExten$, pDest$) AS INTEGER
  22. DECLARE FUNCTION VFindExe(pFName$, pFExten$, pDest$) AS INTEGER
  23. DECLARE FUNCTION VIsSystemAdequate AS INTEGER
  24.  
  25.  
  26.  
  27. '----------------------------------------------------------------
  28. '- Purpose:
  29. '-         to have cheap quicky way to message boxes
  30. '- Arguments:
  31. '-         the text message and the dialog title
  32. '- Returns:
  33. '-         nothing
  34. '----------------------------------------------------------------
  35. SUB VMessageBox(msg$, title$) STATIC
  36.  
  37.     i% = DoMsgBox(msg$, title$, MB_ICONEXCLAMATION+MB_OK)
  38.  
  39. END SUB
  40.  
  41.  
  42. '----------------------------------------------------------------
  43. '- Purpose:
  44. '-         to do quicky debug messages
  45. '- Arguments:
  46. '-         the text message and the dialog title
  47. '- Returns:
  48. '-         nothing
  49. '----------------------------------------------------------------
  50. SUB VDbgMsgBox(msg$, title$) STATIC
  51.  
  52. '$IFDEF DEBUG
  53.     VMessageBox msg$, title$
  54. '$ENDIF 'DEBUG
  55.  
  56. END SUB
  57.  
  58.  
  59. '----------------------------------------------------------------
  60. '- Purpose:
  61. '-     Appends a file name to the end of a directory path,
  62. '-     inserting a backslash character if needed.
  63. '- Arguments:
  64. '-     szDir$  - full directory path (with optional ending "\")
  65. '-     szFile$ - filename to append to directory
  66. '- Returns:
  67. '-     Resulting fully qualified path name.
  68. '----------------------------------------------------------------
  69. FUNCTION VMakePath (szDir$, szFile$) STATIC  AS STRING
  70.     IF szDir$ = "" THEN
  71.         VMakePath = szFile$
  72.     ELSEIF szFile$ = "" THEN
  73.         VMakePath = szDir$
  74.     ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
  75.         VMakePath = szDir$ + szFile$
  76.     ELSE
  77.         VMakePath = szDir$ + "\" + szFile$
  78.     END IF
  79. END FUNCTION
  80.  
  81.  
  82. '----------------------------------------------------------------
  83. '----------------------------------------------------------------
  84. '' From the MS Knowledge Base CD #2:
  85. ''following were taken from windows.h. &H means they're hex
  86. CONST WS_VISIBLE=&H10000000
  87. CONST WS_BORDER =&H00800000
  88. CONST WS_CLIPCHILDREN =&H02000000
  89. CONST GWL_STYLE =-16
  90. CONST SW_SHOWMAXIMIZED=3
  91.  
  92. DECLARE FUNCTION ShowWindow  LIB "user.exe" (hWnd%,iShow%) AS INTEGER
  93. DECLARE FUNCTION SetWindowLong LIB "user.exe" (hWnd%, offset%, style&) AS LONG
  94.  
  95.  
  96. SUB VMaximizeFrame STATIC
  97.     hWnd%=HwndFrame()
  98.     i&=SetWindowLong(hWnd%,GWL_STYLE,WS_VISIBLE+WS_BORDER+WS_CLIPCHILDREN)
  99.     j%=ShowWindow(hWnd%,SW_SHOWMAXIMIZED)
  100. END SUB
  101.  
  102. '----------------------------------------------------------------
  103. '----------------------------------------------------------------
  104. FUNCTION VFindExeFromRegistration (pFExten$, pDest$) STATIC AS INTEGER
  105.     '' set the local vars.
  106.     lDestDir$ = ""
  107.     lDrive$ = ""
  108.     CursorSave% = ShowWaitCursor()
  109.  
  110.  
  111.    '' step one:  try to find the file in the win.ini extensions section.
  112.     IF pFExten$ <> "" THEN
  113.         lDrive$ = GetIniKeyString("WIN.INI", "Extensions", pFExten$)
  114.  
  115.         VDbgMsgBox "Extension entry from Win.ini: " + lDrive$, "VRDEBUG"
  116.  
  117.         IF lDrive$ <> "" THEN  ''there is a key
  118.             ''remove the tail (^.VVR)
  119.             StrLen% = LEN(lDrive$)
  120.             WHILE (MID$(lDrive$, StrLen%, 1) <> "^") AND (StrLen% > 1)
  121.                 StrLen% = StrLen% - 1
  122.             WEND
  123.             StrLen% = StrLen% - 1
  124.  
  125.             TNAME$ = MID$(lDrive$, 1, StrLen%)
  126.             lDrive$ = RTRIM$(TNAME$)
  127.  
  128.             StrLen% = DoesFileExist(lDrive$, femExists) '' file still there?
  129.  
  130.             IF StrLen% = 0 THEN
  131.                 tempStr$ = FindTargetOnEnvVar(lDrive$, "PATH")
  132.                 IF tempStr$ <> "" THEN
  133.                     StrLen% = DoesFileExist(tempStr$, femExists)
  134.                     IF StrLen% = 1 THEN '' file exists
  135.                         lDrive$ = tempStr$
  136.                     END IF
  137.                 END IF
  138.             END IF
  139.  
  140.             VDbgMsgBox "After stripping the file type:  " + lDrive$, "VRDEBUG"
  141.  
  142.             IF StrLen% = 1 THEN   '' file still there!
  143.                 StrLen% = LEN(lDrive$)
  144.  
  145.                 '' Extract directory name
  146.                 WHILE (MID$(lDrive$, StrLen%, 1) <> "\") AND (StrLen% > 1)
  147.                     StrLen% = StrLen% - 1
  148.                 WEND
  149.                 StrLen% = StrLen% - 1
  150.  
  151.                 lDestDir$ = MID$(lDrive$, 1, StrLen%)
  152.  
  153.  
  154.                 VDbgMsgBox "Dir name:  " + lDestDir$, "lDestDir"
  155.  
  156.  
  157.                 '' Directory okay?
  158.                 i% = DoesDirExist(lDestDir$)
  159.                 IF i% = 0 THEN
  160.                     lDrive$ = ""
  161.                     lDestDir$ = ""
  162.                 END IF
  163.                 
  164.             ELSE  '' no key.  Poop.
  165.                 lDrive$ = ""
  166.                 lDestDir$ = ""
  167.             END IF
  168.         ENDIF
  169. '$IFDEF DEBUG
  170.     ELSE
  171.         VMessageBox "No file extension passed to VFindExe", "VFindExe Debug"
  172. '$ENDIF 'DEBUG
  173.     ENDIF
  174.  
  175.     '' can't find it;  punt!
  176.     IF lDestDir$ = "" THEN
  177.  
  178.         VDbgMsgBox "Can't find exe anywhere", "VFindExeFromRegistration Debug"
  179.  
  180.         pDest$ = ""
  181.         VFindExeFromRegistration = 0
  182.      ELSE
  183.         pDest$ = lDestDir$
  184.         VFindExeFromRegistration = 1
  185.     ENDIF
  186.  
  187.     RestoreCursor CursorSave%
  188.  
  189. END FUNCTION
  190.  
  191. '----------------------------------------------------------------
  192. '----------------------------------------------------------------
  193. FUNCTION VFindExe (pFName$, pFExten$, pDest$) STATIC AS INTEGER
  194. '$ifdef DEBUG
  195.     if pFName$ = "" then
  196.         BadArgErr 1, "VFindExe", pFName$
  197.     end if
  198. '$endif ''DEBUG
  199.     '' set the local vars.
  200.     lDestDir$ = ""
  201.     lDrive$ = ""
  202.  
  203.  
  204.    '' step one:  try to find the file in the win.ini extensions section.
  205.    found% = VFindExeFromRegistration (pFExten, lDestDir$)
  206.  
  207.     '' step two:  search the hard drive for the exe.
  208.     IF lDestDir$ = "" THEN
  209.         dLetter$ = ""
  210.         LDList$ = "LocalHardDriveList"
  211.  
  212.  
  213.         VDbgMsgBox "Can't find exe from win.ini", "VFindExe Debug"
  214.  
  215.         OldCursor% = ShowWaitCursor()    '' set waiting cursor
  216.         sz$ = UIStartDlg("mscuistf.dll", LOOKFORFILE_DLG, "FModelessDlgProc", 0, "")
  217.         GetLocalHardDrivesList LDList$
  218.         DListLength% = GetListLength(LDList$)
  219.         FOR i% = 1 TO DListLength% STEP 1
  220.             dLetter$ = GetListItem(LDList$, i%)
  221.             IF (dLetter$ <> "" AND lDestDir$ = "") THEN
  222.                 lDrive$ = dLetter$ + ":\"
  223.                 lDestDir$ = FindFileInTree(pFName$, lDrive$)
  224.              ENDIF
  225.         NEXT i%
  226.  
  227.  
  228.         VDbgMsgBox "found an exe in " + lDestDir$, "VFindExe" 
  229.  
  230.  
  231.         IF lDestDir$ <> "" THEN
  232.             lDrive$ = lDestDir$
  233.             StrLen% = LEN(lDrive$)
  234.  
  235.             '' Extract directory name
  236.             WHILE (MID$(lDrive$, StrLen%, 1) <> "\") AND (StrLen% > 1)
  237.                 StrLen% = StrLen% - 1
  238.             WEND
  239.             StrLen% = StrLen% - 1
  240.  
  241.             lDestDir$ = MID$(lDrive$, 1, StrLen%)
  242.         END IF
  243.  
  244.         UIPop 1
  245.         RestoreCursor OldCursor%
  246.     END IF
  247.  
  248.     '' step three:  punt!
  249.     IF lDestDir$ = "" THEN
  250.  
  251.  
  252.         VDbgMsgBox "Can't find exe anywhere", "VFindExe Debug"
  253.  
  254.         pDest$ = ""
  255.         VFindExe = 0
  256.      ELSE
  257.         pDest$ = lDestDir$
  258.         VFindExe = 1
  259.     ENDIF
  260.  
  261. END FUNCTION
  262.  
  263.  
  264.  
  265.  
  266. '----------------------------------------------------------------
  267. '- Purpose:
  268. '-         to check if the user's system can handle our stuff.
  269. '-           (Win 3.1 on a 386 or better)
  270. '- Arguments:
  271. '-         none.
  272. '- Returns:
  273. '-         TRUE/FALSE if system is up to our products
  274. '----------------------------------------------------------------
  275. FUNCTION VIsSystemAdequate STATIC AS INTEGER
  276.     '' check the windows version and machine type.  Verify that it is capable.
  277.     WinMajVer% = GetWindowsMajorVersion()    '' 3, as in 3.1
  278.     WinMinVer% = GetWindowsMinorVersion()    '' 10, as in 3.10
  279.     Processor% = GetProcessorType()          '' 3(86), 4(86), 5(86)
  280.  
  281.     VIsSystemAdequate = 1
  282.     IF ((WinMajVer% = 3) AND (WinMinVer% < 10)) OR (WinMajVer < 3) THEN
  283.         sz$ = UIStartDlg("mscuistf.dll", NO_WIN_3_1_DLG, "FInfo0DlgProc", 0, "")
  284.         UIPop 1
  285.         VIsSystemAdequate = 0
  286.     ENDIF
  287.  
  288.     IF Processor% < 3 THEN
  289.         sz$ = UIStartDlg("mscuistf.dll", WRONG_CPU_DLG, "FInfo0DlgProc", 0, "")
  290.         UIPop 1
  291.         VIsSystemAdequate = 0
  292.     ENDIF
  293.  
  294. END FUNCTION
  295.  
  296.